package com.shrct.businessprocess.project.impl;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import com.shrct.businessprocess.budget.RCBudget;
import com.shrct.businessprocess.budget.RCCostBreakDown;
import com.shrct.businessprocess.budget.RCSaleContractPayCondition;
import com.shrct.businessprocess.budget.impl.RCCostBreakDownImpl;
import com.shrct.businessprocess.budget.impl.RCSaleContractPayConditionImpl;
import com.shrct.businessprocess.common.CurrencyType;
import com.shrct.businessprocess.common.impl.CurrencyTypeImpl;
import com.shrct.businessprocess.diagnose.DiagnoseItem;
import com.shrct.businessprocess.diagnose.IDiagnoseAcceptor;
import com.shrct.businessprocess.money.Moneys;
import com.shrct.businessprocess.organization.RCBusinessProcessorRoleProvider;
import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.RCEmployeeUser;
import com.shrct.businessprocess.organization.RCEnterprise;
import com.shrct.businessprocess.organization.impl.RCEnterpriseImpl;
import com.shrct.businessprocess.project.RCActualCostReport;
import com.shrct.businessprocess.project.RCCustomerContract;
import com.shrct.businessprocess.project.RCCustomerContractMoneyAccept;
import com.shrct.businessprocess.project.RCEarlyBuildInfo;
import com.shrct.businessprocess.project.RCExchangeRate;
import com.shrct.businessprocess.project.RCInitializeProjectProcess;
import com.shrct.businessprocess.project.RCPaymentProgressItem;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectEvent;
import com.shrct.businessprocess.project.RCProjectInternalStatus;
import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.project.RCProjectSaleAssignment;
import com.shrct.businessprocess.project.RCProjectServiceDeliver;
import com.shrct.businessprocess.project.RCProjectStat;
import com.shrct.businessprocess.project.RCProjectStatus;
import com.shrct.businessprocess.project.RCProjectTypeExtension;
import com.shrct.businessprocess.project.RCRealMoney;
import com.shrct.businessprocess.project.events.RCCustomerContractEventsManager;
import com.shrct.businessprocess.project.events.RCProjectEventsManager;
import com.shrct.businessprocess.project.impl.RCActualCostReportImpl;
import com.shrct.businessprocess.project.impl.RCCustomerContractImpl;
import com.shrct.businessprocess.project.impl.RCExchangeRateImpl;
import com.shrct.businessprocess.project.impl.RCProjectEventImpl;
import com.shrct.businessprocess.project.impl.RCProjectSaleAssignmentImpl;
import com.shrct.businessprocess.project.impl.RCProjectStatImpl;
import com.shrct.businessprocess.project.impl.RCProjectTypeExtensionImpl;
import com.shrct.businessprocess.project.proxy.RCProjectProxy;
import com.shrct.businessprocess.purchase.RCBudgetContract;
import com.shrct.businessprocess.purchase.RCInvoiceType;
import com.shrct.businessprocess.purchase.RCPurchaseIncomeRequest;
import com.shrct.businessprocess.purchase.RCPurchaseInvoiceItem;
import edu.fudan.langlab.domain.common.FileStorage;
import edu.fudan.langlab.domain.common.impl.FileStorageImpl;
import edu.fudan.langlab.domain.security.ISystemUserService;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.langlab.domain.statemachine.ModelObjectLogService;
import edu.fudan.mylang.common.NumberExtensions;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IGenericQuery;
import edu.fudan.mylang.pf.IObjectFactory;
import edu.fudan.mylang.utils.DateUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.Functions.Function2;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("RCPROJECT_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcproject")
public class RCProjectImpl extends BaseModelObject implements RCProject {
  public RCProjectImpl() {
    super();
  }
  
  private RCProjectInternalStatus InternalStatus;
  
  public RCProjectInternalStatus getInternalStatus() {
    return this.InternalStatus;
  }
  
  private ModelObjectLogService getModelObjectLogService() {
    return getBeanFactory().getBean(ModelObjectLogService.class);
  }
  
  private void _start() {
    
    InternalStatus=RCProjectInternalStatus.created;
  }
  
  public void start() {
    if(InternalStatus==null){
    	_start();
    	getModelObjectLogService().createLog(this,"InternalStatus","Start");
    	getBeanFactory().getBean(com.shrct.businessprocess.project.events.RCProjectEventsManager.class).fireStarted(this);					
    }else{
    	throw new edu.fudan.langlab.domain.statemachine.InvalidStateException("allready started");
    }
  }
  
  private void _actFixTimer() {
    
    if ((this.passed).booleanValue()) {
      this.fixActuralCostReport();
    }
  }
  
  public void actFixTimer() {
    if(InternalStatus==RCProjectInternalStatus.created){
    	_actFixTimer();
    	getModelObjectLogService().createLog(this,"InternalStatus","actFixTimer");
    	getBeanFactory().getBean(com.shrct.businessprocess.project.events.RCProjectEventsManager.class).fireActFixTimer(this);						
    }else{
    	throw new edu.fudan.langlab.domain.statemachine.InvalidStateException(InternalStatus.name());
    }
  }
  
  private void _actUpdateTimer() {
    
    if ((this.passed).booleanValue()) {
      this.stat.updateInfo();
    }
  }
  
  public void actUpdateTimer() {
    if(InternalStatus==RCProjectInternalStatus.created){
    	_actUpdateTimer();
    	getModelObjectLogService().createLog(this,"InternalStatus","actUpdateTimer");
    	getBeanFactory().getBean(com.shrct.businessprocess.project.events.RCProjectEventsManager.class).fireActUpdateTimer(this);						
    }else{
    	throw new edu.fudan.langlab.domain.statemachine.InvalidStateException(InternalStatus.name());
    }
  }
  
  public Boolean isCreated() {
    return com.shrct.businessprocess.project.RCProjectInternalStatus.created==InternalStatus;
  }
  
  private String code;
  
  public String getCode() {
    return this.code;
  }
  
  public RCProject setCode(final String code) {
    this.code = code;
    return this;			
    
  }
  
  private String name;
  
  public String getName() {
    return this.name;
  }
  
  public RCProject setName(final String name) {
    this.name = name;
    return this;			
    
  }
  
  @Column(length = 512)
  private String simplePy;
  
  public String getSimplePy() {
    return this.simplePy;
  }
  
  public RCProject setSimplePy(final String simplePy) {
    this.simplePy = simplePy;
    return this;			
    
  }
  
  public String getNameField() {
    return "name";
  }
  
  @JoinColumn(name = "currencyType_id")
  @ManyToOne(targetEntity = CurrencyTypeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private CurrencyType currencyType;
  
  public CurrencyType getCurrencyType() {
    return this.currencyType;
  }
  
  public RCProject setCurrencyType(final CurrencyType currencyType) {
    this.currencyType = currencyType;
    return this;			
    
  }
  
  @JoinColumn(name = "customer_id")
  @ManyToOne(targetEntity = RCEnterpriseImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCEnterprise customer;
  
  public RCEnterprise getCustomer() {
    return this.customer;
  }
  
  public RCProject setCustomer(final RCEnterprise customer) {
    this.customer = customer;
    return this;			
    
  }
  
  private RCProjectStatus status = RCProjectStatus.creating;
  
  public RCProjectStatus getStatus() {
    return this.status;
  }
  
  public RCProject setStatus(final RCProjectStatus status) {
    this.status = status;
    return this;			
    
  }
  
  private Boolean allTaskDelivered = Boolean.valueOf(false);
  
  public Boolean getAllTaskDelivered() {
    return this.allTaskDelivered;
  }
  
  public RCProject setAllTaskDelivered(final Boolean allTaskDelivered) {
    this.allTaskDelivered = allTaskDelivered;
    return this;			
    
  }
  
  private Date deliverDate;
  
  public Date getDeliverDate() {
    return this.deliverDate;
  }
  
  public RCProject setDeliverDate(final Date deliverDate) {
    this.deliverDate = deliverDate;
    return this;			
    
  }
  
  @JoinColumn(name = "typeExtension_id")
  @OneToOne(targetEntity = RCProjectTypeExtensionImpl.class, cascade = CascadeType.ALL)
  private RCProjectTypeExtension typeExtension;
  
  public RCProjectTypeExtension getTypeExtension() {
    return this.typeExtension;
  }
  
  public RCProject setTypeExtension(final RCProjectTypeExtension typeExtension) {
    this.typeExtension = typeExtension;
    return this;			
    
  }
  
  private Boolean isConnected = Boolean.valueOf(false);
  
  public Boolean getIsConnected() {
    return this.isConnected;
  }
  
  public RCProject setIsConnected(final Boolean isConnected) {
    this.isConnected = isConnected;
    return this;			
    
  }
  
  public void delivered(final Date deliverDate) {
    this.allTaskDelivered = Boolean.valueOf(true);
    this.deliverDate = deliverDate;
    this.stat.updateInfo();
  }
  
  public void deliverConfirmed(final Date confirmDate) {
    if ((this.typeExtension instanceof RCProjectServiceDeliver)) {
      final Procedure1<RCProjectServiceDeliver> _function = new Procedure1<RCProjectServiceDeliver>() {
          public void apply(final RCProjectServiceDeliver it) {
            it.setDelivered(Boolean.valueOf(true));
            it.setConfirmDate(confirmDate);
          }
        };
      ObjectExtensions.<RCProjectServiceDeliver>operator_doubleArrow(((RCProjectServiceDeliver) this.typeExtension), _function);
    }
    this.stat.updateInfo();
  }
  
  public RCEmployee getBusinessMan() {
    RCEmployee _businessMan = this.customer.getBusinessMan();
    return _businessMan;
  }
  
  public Integer getYear() {
    String _substring = this.code.substring(0, 4);
    int _parseInt = Integer.parseInt(_substring);
    return Integer.valueOf(_parseInt);
  }
  
  private Boolean actualCostDirtyFlag = Boolean.valueOf(false);
  
  public Boolean getActualCostDirtyFlag() {
    return this.actualCostDirtyFlag;
  }
  
  public RCProject setActualCostDirtyFlag(final Boolean actualCostDirtyFlag) {
    this.actualCostDirtyFlag = actualCostDirtyFlag;
    return this;			
    
  }
  
  private Boolean allContractCollected = Boolean.valueOf(false);
  
  public Boolean getAllContractCollected() {
    return this.allContractCollected;
  }
  
  public RCProject setAllContractCollected(final Boolean allContractCollected) {
    this.allContractCollected = allContractCollected;
    return this;			
    
  }
  
  private Boolean lor = Boolean.valueOf(false);
  
  public Boolean getLor() {
    return this.lor;
  }
  
  public RCProject setLor(final Boolean lor) {
    this.lor = lor;
    return this;			
    
  }
  
  @OneToMany(targetEntity = RCProjectSaleAssignmentImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCProjectSaleAssignment> salers = new java.util.ArrayList<com.shrct.businessprocess.project.RCProjectSaleAssignment>();;
  
  public Collection<RCProjectSaleAssignment> getSalers() {
    return this.salers;
  }
  
  public RCProjectSaleAssignment createAndAddtoSalers() {
    getSalers().size();
    com.shrct.businessprocess.project.RCProjectSaleAssignment rCProjectSaleAssignment = new com.shrct.businessprocess.project.impl.RCProjectSaleAssignmentImpl(this);
    getObjectFactory().create(rCProjectSaleAssignment);
    getSalers().add(rCProjectSaleAssignment);
    return rCProjectSaleAssignment;
    
  }
  
  public RCProjectSaleAssignment createAndAddtoSalers(final Procedure1<RCProjectSaleAssignment> updater) {
    getSalers().size();
    com.shrct.businessprocess.project.RCProjectSaleAssignment rCProjectSaleAssignment = new com.shrct.businessprocess.project.impl.RCProjectSaleAssignmentImpl(this);
    getObjectFactory().create(rCProjectSaleAssignment);
    getSalers().add(rCProjectSaleAssignment);
    return rCProjectSaleAssignment;
    
  }
  
  public RCProject removeAllSalers() {
    for(RCProjectSaleAssignment obj : this.salers){
    	getObjectFactory().delete(obj);
    }
    this.salers.clear();
    return this;	
    
  }
  
  public RCProject removeFromSalers(final RCProjectSaleAssignment rCProjectSaleAssignment) {
    this.salers.remove(rCProjectSaleAssignment);
    getObjectFactory().delete(rCProjectSaleAssignment);
    return this;
    
  }
  
  @JoinColumn(name = "cbd_id")
  @OneToOne(targetEntity = RCCostBreakDownImpl.class, cascade = CascadeType.ALL)
  private RCCostBreakDown cbd;
  
  public RCCostBreakDown getCbd() {
    return this.cbd;
  }
  
  public RCProject setCbd(final RCCostBreakDown cbd) {
    this.cbd = cbd;
    return this;			
    
  }
  
  @OneToMany(targetEntity = RCExchangeRateImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCExchangeRate> exchangeRates = new java.util.ArrayList<com.shrct.businessprocess.project.RCExchangeRate>();;
  
  public Collection<RCExchangeRate> getExchangeRates() {
    return this.exchangeRates;
  }
  
  public RCExchangeRate createAndAddtoExchangeRates() {
    getExchangeRates().size();
    com.shrct.businessprocess.project.RCExchangeRate rCExchangeRate = new com.shrct.businessprocess.project.impl.RCExchangeRateImpl(this);
    getObjectFactory().create(rCExchangeRate);
    getExchangeRates().add(rCExchangeRate);
    return rCExchangeRate;
    
  }
  
  public RCExchangeRate createAndAddtoExchangeRates(final Procedure1<RCExchangeRate> updater) {
    getExchangeRates().size();
    com.shrct.businessprocess.project.RCExchangeRate rCExchangeRate = new com.shrct.businessprocess.project.impl.RCExchangeRateImpl(this);
    getObjectFactory().create(rCExchangeRate);
    getExchangeRates().add(rCExchangeRate);
    return rCExchangeRate;
    
  }
  
  public RCProject removeAllExchangeRates() {
    for(RCExchangeRate obj : this.exchangeRates){
    	getObjectFactory().delete(obj);
    }
    this.exchangeRates.clear();
    return this;	
    
  }
  
  public RCProject removeFromExchangeRates(final RCExchangeRate rCExchangeRate) {
    this.exchangeRates.remove(rCExchangeRate);
    getObjectFactory().delete(rCExchangeRate);
    return this;
    
  }
  
  @OneToMany(targetEntity = RCProjectEventImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCProjectEvent> events = new java.util.ArrayList<com.shrct.businessprocess.project.RCProjectEvent>();;
  
  public Collection<RCProjectEvent> getEvents() {
    return this.events;
  }
  
  public RCProjectEvent createAndAddtoEvents() {
    getEvents().size();
    com.shrct.businessprocess.project.RCProjectEvent rCProjectEvent = new com.shrct.businessprocess.project.impl.RCProjectEventImpl(this);
    getObjectFactory().create(rCProjectEvent);
    getEvents().add(rCProjectEvent);
    return rCProjectEvent;
    
  }
  
  public RCProjectEvent createAndAddtoEvents(final Procedure1<RCProjectEvent> updater) {
    getEvents().size();
    com.shrct.businessprocess.project.RCProjectEvent rCProjectEvent = new com.shrct.businessprocess.project.impl.RCProjectEventImpl(this);
    getObjectFactory().create(rCProjectEvent);
    getEvents().add(rCProjectEvent);
    return rCProjectEvent;
    
  }
  
  public RCProject removeAllEvents() {
    for(RCProjectEvent obj : this.events){
    	getObjectFactory().delete(obj);
    }
    this.events.clear();
    return this;	
    
  }
  
  public RCProject removeFromEvents(final RCProjectEvent rCProjectEvent) {
    this.events.remove(rCProjectEvent);
    getObjectFactory().delete(rCProjectEvent);
    return this;
    
  }
  
  @OneToMany(targetEntity = RCCustomerContractImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCCustomerContract> contracts = new java.util.ArrayList<com.shrct.businessprocess.project.RCCustomerContract>();;
  
  public Collection<RCCustomerContract> getContracts() {
    return this.contracts;
  }
  
  public RCCustomerContract createAndAddtoContracts() {
    getContracts().size();
    com.shrct.businessprocess.project.RCCustomerContract rCCustomerContract = new com.shrct.businessprocess.project.impl.RCCustomerContractImpl(this);
    getObjectFactory().create(rCCustomerContract);
    getContracts().add(rCCustomerContract);
    return rCCustomerContract;
    
  }
  
  public RCCustomerContract createAndAddtoContracts(final Procedure1<RCCustomerContract> updater) {
    getContracts().size();
    com.shrct.businessprocess.project.RCCustomerContract rCCustomerContract = new com.shrct.businessprocess.project.impl.RCCustomerContractImpl(this);
    getObjectFactory().create(rCCustomerContract);
    getContracts().add(rCCustomerContract);
    return rCCustomerContract;
    
  }
  
  public RCProject removeAllContracts() {
    for(RCCustomerContract obj : this.contracts){
    	getObjectFactory().delete(obj);
    }
    this.contracts.clear();
    return this;	
    
  }
  
  public RCProject removeFromContracts(final RCCustomerContract rCCustomerContract) {
    this.contracts.remove(rCCustomerContract);
    getObjectFactory().delete(rCCustomerContract);
    return this;
    
  }
  
  @OneToMany(targetEntity = RCSaleContractPayConditionImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCSaleContractPayCondition> payConditions = new java.util.ArrayList<com.shrct.businessprocess.budget.RCSaleContractPayCondition>();;
  
  public Collection<RCSaleContractPayCondition> getPayConditions() {
    return this.payConditions;
  }
  
  public RCSaleContractPayCondition createAndAddtoPayConditions() {
    getPayConditions().size();
    com.shrct.businessprocess.budget.RCSaleContractPayCondition rCSaleContractPayCondition = new com.shrct.businessprocess.budget.impl.RCSaleContractPayConditionImpl(this);
    getObjectFactory().create(rCSaleContractPayCondition);
    getPayConditions().add(rCSaleContractPayCondition);
    return rCSaleContractPayCondition;
    
  }
  
  public RCSaleContractPayCondition createAndAddtoPayConditions(final Procedure1<RCSaleContractPayCondition> updater) {
    getPayConditions().size();
    com.shrct.businessprocess.budget.RCSaleContractPayCondition rCSaleContractPayCondition = new com.shrct.businessprocess.budget.impl.RCSaleContractPayConditionImpl(this);
    getObjectFactory().create(rCSaleContractPayCondition);
    getPayConditions().add(rCSaleContractPayCondition);
    return rCSaleContractPayCondition;
    
  }
  
  public RCProject removeAllPayConditions() {
    for(RCSaleContractPayCondition obj : this.payConditions){
    	getObjectFactory().delete(obj);
    }
    this.payConditions.clear();
    return this;	
    
  }
  
  public RCProject removeFromPayConditions(final RCSaleContractPayCondition rCSaleContractPayCondition) {
    this.payConditions.remove(rCSaleContractPayCondition);
    getObjectFactory().delete(rCSaleContractPayCondition);
    return this;
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "isEarlyBuild", column = @Column(name = "earlyBuildInfo_isEarlyBuild") ), @AttributeOverride(name = "planContractDate", column = @Column(name = "earlyBuildInfo_planContractDate") ), @AttributeOverride(name = "acturalContractDate", column = @Column(name = "earlyBuildInfo_acturalContractDate") ), @AttributeOverride(name = "comment", column = @Column(name = "earlyBuildInfo_comment") ), @AttributeOverride(name = "workaround", column = @Column(name = "earlyBuildInfo_workaround") ) } )
  @AssociationOverrides(value = { } )
  private RCEarlyBuildInfo earlyBuildInfo = com.shrct.businessprocess.project.RCEarlyBuildInfo.create();
  
  public RCEarlyBuildInfo getEarlyBuildInfo() {
    return this.earlyBuildInfo;
  }
  
  public RCProject setEarlyBuildInfo(final RCEarlyBuildInfo earlyBuildInfo) {
    this.earlyBuildInfo = earlyBuildInfo;
    return this;			
    
  }
  
  private Boolean passed = Boolean.valueOf(false);
  
  public Boolean getPassed() {
    return this.passed;
  }
  
  public RCProject setPassed(final Boolean passed) {
    this.passed = passed;
    return this;			
    
  }
  
  private Date passDate;
  
  public Date getPassDate() {
    return this.passDate;
  }
  
  public RCProject setPassDate(final Date passDate) {
    this.passDate = passDate;
    return this;			
    
  }
  
  @ManyToMany(targetEntity = FileStorageImpl.class)
  @JoinTable(name = "m2m_rcproject_attachedfiles", joinColumns = @JoinColumn(name = "rcproject_id") , inverseJoinColumns = @JoinColumn(name = "fileStorage_inv_id") )
  private Collection<FileStorage> attachedFiles = new java.util.ArrayList<edu.fudan.langlab.domain.common.FileStorage>();;
  
  public Collection<FileStorage> getAttachedFiles() {
    return this.attachedFiles;
  }
  
  public RCProject setAttachedFiles(final Iterable<FileStorage> attachedFiles) {
    removeAllAttachedFiles();
    for(FileStorage ca : attachedFiles){
    	addtoAttachedFiles(ca);
    }
    return this;		
    
  }
  
  public RCProject addtoAttachedFiles(final FileStorage fileStorage) {
    this.attachedFiles.add(fileStorage);
    return this;
    
  }
  
  public RCProject removeAllAttachedFiles() {
    this.attachedFiles.clear();
    return this;	
    
  }
  
  public RCProject removeFromAttachedFiles(final FileStorage fileStorage) {
    this.attachedFiles.remove(fileStorage);
    return this;
    
  }
  
  public void updateLORInfo() {
    final Procedure1<RCProjectSaleAssignment> _function = new Procedure1<RCProjectSaleAssignment>() {
        public void apply(final RCProjectSaleAssignment it) {
          Double _rate = it.getRate();
          it.setLorRate(_rate);
        }
      };
    IterableExtensions.<RCProjectSaleAssignment>forEach(this.salers, _function);
    if ((this.lor).booleanValue()) {
      final Function1<RCProjectSaleAssignment,Boolean> _function_1 = new Function1<RCProjectSaleAssignment,Boolean>() {
          public Boolean apply(final RCProjectSaleAssignment it) {
            Boolean _isMajor = it.getIsMajor();
            return _isMajor;
          }
        };
      Iterable<RCProjectSaleAssignment> _filter = IterableExtensions.<RCProjectSaleAssignment>filter(this.salers, _function_1);
      final RCProjectSaleAssignment major = IterableExtensions.<RCProjectSaleAssignment>head(_filter);
      int _plus = (100 + 100);
      Double _rate = major.getRate();
      double _minus = (_plus - (_rate).doubleValue());
      double _min = Math.min(_minus, 130d);
      Double _rate_1 = major.getRate();
      double _minus_1 = (100 - (_rate_1).doubleValue());
      double _minus_2 = (_min - _minus_1);
      major.setLorRate(Double.valueOf(_minus_2));
    }
  }
  
  public void markAllContractCollected() {
    this.allContractCollected = Boolean.valueOf(true);
    BeanFactory _beanFactory = this.getBeanFactory();
    RCProjectEventsManager _bean = _beanFactory.<RCProjectEventsManager>getBean(RCProjectEventsManager.class);
    _bean.fireNotifyAllContractCollected(this);
  }
  
  public Collection<RCExchangeRate> geters() {
    return this.exchangeRates;
  }
  
  public RCEmployee getMajorSales() {
    final Function1<RCProjectSaleAssignment,Boolean> _function = new Function1<RCProjectSaleAssignment,Boolean>() {
        public Boolean apply(final RCProjectSaleAssignment it) {
          Boolean _isMajor = it.getIsMajor();
          return _isMajor;
        }
      };
    RCProjectSaleAssignment _findFirst = IterableExtensions.<RCProjectSaleAssignment>findFirst(this.salers, _function);
    RCEmployee _employee = _findFirst==null?(RCEmployee)null:_findFirst.getEmployee();
    return _employee;
  }
  
  public String getEntityName() {
    String _xifexpression = null;
    boolean _equals = Objects.equal(this.code, null);
    if (_equals) {
      _xifexpression = this.name;
    } else {
      String _plus = (this.name + "(");
      String _plus_1 = (_plus + this.code);
      String _plus_2 = (_plus_1 + ")");
      _xifexpression = _plus_2;
    }
    return _xifexpression;
  }
  
  public RCInitializeProjectProcess getInitializeProcess() {
    IGenericQuery<RCInitializeProjectProcess> query=getObjectFactory().createGenericQuery(RCInitializeProjectProcess.class,"select p from com.shrct.businessprocess.project.impl.RCInitializeProjectProcessImpl as p   where ((p.project) = (:this)) and  p.active = 1      ").setParameter("this",this);
    RCInitializeProjectProcess _uniqueResult = query.uniqueResult();
    return _uniqueResult;
  }
  
  public RCProjectMoney getTotalCustomerContractAmount() {
    final Function1<RCCustomerContract,RCProjectMoney> _function = new Function1<RCCustomerContract,RCProjectMoney>() {
        public RCProjectMoney apply(final RCCustomerContract it) {
          RCProjectMoney _totalContractAmount = it.getTotalContractAmount();
          return _totalContractAmount;
        }
      };
    Iterable<RCProjectMoney> _map = IterableExtensions.<RCCustomerContract, RCProjectMoney>map(this.contracts, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCProjectMoney _sum = Moneys.sum(_map, _defaultExchangeRate);
    return _sum;
  }
  
  public RCProjectMoney getTotalContractAmount() {
    RCProjectMoney _xifexpression = null;
    if ((this.allContractCollected).booleanValue()) {
      final Function1<RCCustomerContract,RCProjectMoney> _function = new Function1<RCCustomerContract,RCProjectMoney>() {
          public RCProjectMoney apply(final RCCustomerContract it) {
            RCProjectMoney _totalContractAmount = it.getTotalContractAmount();
            return _totalContractAmount;
          }
        };
      Iterable<RCProjectMoney> _map = IterableExtensions.<RCCustomerContract, RCProjectMoney>map(this.contracts, _function);
      RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
      RCProjectMoney _sum = Moneys.sum(_map, _defaultExchangeRate);
      _xifexpression = _sum;
    } else {
      Collection<RCBudget> _budgets = this.cbd.getBudgets();
      final Function1<RCBudget,RCProjectMoney> _function_1 = new Function1<RCBudget,RCProjectMoney>() {
          public RCProjectMoney apply(final RCBudget it) {
            RCProjectMoney _contractPrice = it.getContractPrice();
            return _contractPrice;
          }
        };
      Iterable<RCProjectMoney> _map_1 = IterableExtensions.<RCBudget, RCProjectMoney>map(_budgets, _function_1);
      RCExchangeRate _defaultExchangeRate_1 = this.getDefaultExchangeRate();
      RCProjectMoney _sum_1 = Moneys.sum(_map_1, _defaultExchangeRate_1);
      _xifexpression = _sum_1;
    }
    return _xifexpression;
  }
  
  public RCProjectMoney getTotalContractAmount(final RCEnterprise customer) {
    RCProjectMoney _xblockexpression = null;
    {
      Collection<RCBudget> _budgets = this.cbd.getBudgets();
      final Function1<RCBudget,Collection<RCBudgetContract>> _function = new Function1<RCBudget,Collection<RCBudgetContract>>() {
          public Collection<RCBudgetContract> apply(final RCBudget it) {
            Collection<RCBudgetContract> _contracts = it.getContracts();
            return _contracts;
          }
        };
      Iterable<Collection<RCBudgetContract>> _map = IterableExtensions.<RCBudget, Collection<RCBudgetContract>>map(_budgets, _function);
      Iterable<RCBudgetContract> _flatten = Iterables.<RCBudgetContract>concat(_map);
      final Function1<RCBudgetContract,Boolean> _function_1 = new Function1<RCBudgetContract,Boolean>() {
          public Boolean apply(final RCBudgetContract it) {
            RCEnterprise _customer = it.getCustomer();
            boolean _equals = Objects.equal(_customer, customer);
            return Boolean.valueOf(_equals);
          }
        };
      final Iterable<RCBudgetContract> contracts = IterableExtensions.<RCBudgetContract>filter(_flatten, _function_1);
      final Function1<RCBudgetContract,RCProjectMoney> _function_2 = new Function1<RCBudgetContract,RCProjectMoney>() {
          public RCProjectMoney apply(final RCBudgetContract it) {
            RCProjectMoney _totalAmount = it.getTotalAmount();
            return _totalAmount;
          }
        };
      Iterable<RCProjectMoney> _map_1 = IterableExtensions.<RCBudgetContract, RCProjectMoney>map(contracts, _function_2);
      RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
      RCProjectMoney _sum = Moneys.sum(_map_1, _defaultExchangeRate);
      _xblockexpression = (_sum);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getTotalContractAmount(final RCCustomerContract customerContract) {
    RCProjectMoney _xblockexpression = null;
    {
      Collection<RCBudget> _budgets = this.cbd.getBudgets();
      final Function1<RCBudget,Collection<RCBudgetContract>> _function = new Function1<RCBudget,Collection<RCBudgetContract>>() {
          public Collection<RCBudgetContract> apply(final RCBudget it) {
            Collection<RCBudgetContract> _contracts = it.getContracts();
            return _contracts;
          }
        };
      Iterable<Collection<RCBudgetContract>> _map = IterableExtensions.<RCBudget, Collection<RCBudgetContract>>map(_budgets, _function);
      Iterable<RCBudgetContract> _flatten = Iterables.<RCBudgetContract>concat(_map);
      final Function1<RCBudgetContract,Boolean> _function_1 = new Function1<RCBudgetContract,Boolean>() {
          public Boolean apply(final RCBudgetContract it) {
            RCCustomerContract _customerContract = it.getCustomerContract();
            boolean _equals = Objects.equal(_customerContract, customerContract);
            return Boolean.valueOf(_equals);
          }
        };
      final Iterable<RCBudgetContract> contracts = IterableExtensions.<RCBudgetContract>filter(_flatten, _function_1);
      final Function1<RCBudgetContract,RCProjectMoney> _function_2 = new Function1<RCBudgetContract,RCProjectMoney>() {
          public RCProjectMoney apply(final RCBudgetContract it) {
            RCProjectMoney _totalAmount = it.getTotalAmount();
            return _totalAmount;
          }
        };
      Iterable<RCProjectMoney> _map_1 = IterableExtensions.<RCBudgetContract, RCProjectMoney>map(contracts, _function_2);
      RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
      RCProjectMoney _sum = Moneys.sum(_map_1, _defaultExchangeRate);
      _xblockexpression = (_sum);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getTotalBudgetContractAmount() {
    Collection<RCBudget> _budgets = this.cbd.getBudgets();
    final Function1<RCBudget,RCProjectMoney> _function = new Function1<RCBudget,RCProjectMoney>() {
        public RCProjectMoney apply(final RCBudget it) {
          RCProjectMoney _contractPrice = it.getContractPrice();
          return _contractPrice;
        }
      };
    Iterable<RCProjectMoney> _map = IterableExtensions.<RCBudget, RCProjectMoney>map(_budgets, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCProjectMoney _sum = Moneys.sum(_map, _defaultExchangeRate);
    return _sum;
  }
  
  /**
   * 总成本
   */
  public RCProjectMoney getTotalBudgetNetAmount() {
    Collection<RCBudget> _budgets = this.cbd.getBudgets();
    final Function1<RCBudget,RCProjectMoney> _function = new Function1<RCBudget,RCProjectMoney>() {
        public RCProjectMoney apply(final RCBudget it) {
          RCProjectMoney _netPrice = it.getNetPrice();
          return _netPrice;
        }
      };
    Iterable<RCProjectMoney> _map = IterableExtensions.<RCBudget, RCProjectMoney>map(_budgets, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCProjectMoney _sum = Moneys.sum(_map, _defaultExchangeRate);
    return _sum;
  }
  
  public RCRealMoney getTotalPaidAmount() {
    Collection<RCBudget> _budgets = this.cbd.getBudgets();
    final Function1<RCBudget,RCRealMoney> _function = new Function1<RCBudget,RCRealMoney>() {
        public RCRealMoney apply(final RCBudget it) {
          RCRealMoney _totalPaiedAmount = it.getTotalPaiedAmount();
          return _totalPaiedAmount;
        }
      };
    Iterable<RCRealMoney> _map = IterableExtensions.<RCBudget, RCRealMoney>map(_budgets, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCRealMoney _sumRealMoney = Moneys.sumRealMoney(_map, _defaultExchangeRate);
    return _sumRealMoney;
  }
  
  /**
   * 指定合同的实际到款总额
   */
  public RCRealMoney getTotalIncomeAmount(final RCCustomerContract customerContract) {
    RCRealMoney _totalAcceptedAmount = customerContract.getTotalAcceptedAmount();
    return _totalAcceptedAmount;
  }
  
  public RCRealMoney getTotalIncomeAmount() {
    final Function1<RCCustomerContract,RCRealMoney> _function = new Function1<RCCustomerContract,RCRealMoney>() {
        public RCRealMoney apply(final RCCustomerContract it) {
          RCRealMoney _totalIncomeAmount = RCProjectImpl.this.getTotalIncomeAmount(it);
          return _totalIncomeAmount;
        }
      };
    Iterable<RCRealMoney> _map = IterableExtensions.<RCCustomerContract, RCRealMoney>map(this.contracts, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCRealMoney _sumRealMoney = Moneys.sumRealMoney(_map, _defaultExchangeRate);
    return _sumRealMoney;
  }
  
  public RCProjectMoney getTotalInvoiceAmount(final RCCustomerContract customerContract) {
    RCProjectMoney _totalInvoiceAmount = customerContract.getTotalInvoiceAmount();
    return _totalInvoiceAmount;
  }
  
  /**
   * 开票金额
   */
  public RCProjectMoney getTotalInvoiceAmount() {
    final Function1<RCCustomerContract,RCProjectMoney> _function = new Function1<RCCustomerContract,RCProjectMoney>() {
        public RCProjectMoney apply(final RCCustomerContract it) {
          RCProjectMoney _totalInvoiceAmount = it.getTotalInvoiceAmount();
          return _totalInvoiceAmount;
        }
      };
    Iterable<RCProjectMoney> _map = IterableExtensions.<RCCustomerContract, RCProjectMoney>map(this.contracts, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCProjectMoney _sum = Moneys.sum(_map, _defaultExchangeRate);
    return _sum;
  }
  
  /**
   * 收款金额
   */
  public Double getTotalAcceptedAmount() {
    final Function1<RCCustomerContract,RCRealMoney> _function = new Function1<RCCustomerContract,RCRealMoney>() {
        public RCRealMoney apply(final RCCustomerContract it) {
          RCRealMoney _totalAcceptedAmount = it.getTotalAcceptedAmount();
          return _totalAcceptedAmount;
        }
      };
    Iterable<RCRealMoney> _map = IterableExtensions.<RCCustomerContract, RCRealMoney>map(this.contracts, _function);
    RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
    RCRealMoney _sumRealMoney = Moneys.sumRealMoney(_map, _defaultExchangeRate);
    Double _hostAmount = _sumRealMoney.toHostAmount();
    Double _nullsafe = NumberExtensions.nullsafe(_hostAmount);
    final Procedure1<Double> _function_1 = new Procedure1<Double>() {
        public void apply(final Double it) {
          String _plus = ("=======>getTotalAcceptedAmount:" + it);
          InputOutput.<String>println(_plus);
        }
      };
    Double _doubleArrow = ObjectExtensions.<Double>operator_doubleArrow(_nullsafe, _function_1);
    return _doubleArrow;
  }
  
  /**
   * 累计销项税
   */
  public Double getTotalInvoiceTaxAmount() {
    Double _totalIncomeTaxAmount = this.getTotalIncomeTaxAmount();
    Double _calcPercent = this.typeExtension.calcPercent();
    double _multiply = DoubleExtensions.operator_multiply(_totalIncomeTaxAmount, _calcPercent);
    return Double.valueOf(_multiply);
  }
  
  /**
   * 销项税总额=实际开票金额*实际开票税率/（1+实际开票税率）+（合同总额-实际开票金额）*CBD填写税率/（1+CBD填写税率）
   */
  public Double getTotalIncomeTaxAmount() {
    double _xblockexpression = (double) 0;
    {
      final Function1<RCCustomerContract,Double> _function = new Function1<RCCustomerContract,Double>() {
          public Double apply(final RCCustomerContract it) {
            Double _incomeTax = it.getIncomeTax();
            return _incomeTax;
          }
        };
      Iterable<Double> _map = IterableExtensions.<RCCustomerContract, Double>map(this.contracts, _function);
      final Function2<Double,Double,Double> _function_1 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce = IterableExtensions.<Double>reduce(_map, _function_1);
      final Double invoiceTax = NumberExtensions.nullsafe(_reduce);
      final Function1<RCCustomerContract,Collection<RCPurchaseIncomeRequest>> _function_2 = new Function1<RCCustomerContract,Collection<RCPurchaseIncomeRequest>>() {
          public Collection<RCPurchaseIncomeRequest> apply(final RCCustomerContract it) {
            Collection<RCPurchaseIncomeRequest> _incomeRequests = it.getIncomeRequests();
            return _incomeRequests;
          }
        };
      Iterable<Collection<RCPurchaseIncomeRequest>> _map_1 = IterableExtensions.<RCCustomerContract, Collection<RCPurchaseIncomeRequest>>map(this.contracts, _function_2);
      Iterable<RCPurchaseIncomeRequest> _flatten = Iterables.<RCPurchaseIncomeRequest>concat(_map_1);
      final Function1<RCPurchaseIncomeRequest,Boolean> _function_3 = new Function1<RCPurchaseIncomeRequest,Boolean>() {
          public Boolean apply(final RCPurchaseIncomeRequest it) {
            Boolean _isPassed = it.getIsPassed();
            return _isPassed;
          }
        };
      Iterable<RCPurchaseIncomeRequest> _filter = IterableExtensions.<RCPurchaseIncomeRequest>filter(_flatten, _function_3);
      final Function1<RCPurchaseIncomeRequest,Collection<RCPurchaseInvoiceItem>> _function_4 = new Function1<RCPurchaseIncomeRequest,Collection<RCPurchaseInvoiceItem>>() {
          public Collection<RCPurchaseInvoiceItem> apply(final RCPurchaseIncomeRequest it) {
            Collection<RCPurchaseInvoiceItem> _items = it.getItems();
            return _items;
          }
        };
      Iterable<Collection<RCPurchaseInvoiceItem>> _map_2 = IterableExtensions.<RCPurchaseIncomeRequest, Collection<RCPurchaseInvoiceItem>>map(_filter, _function_4);
      final Iterable<RCPurchaseInvoiceItem> allInvoiceItems = Iterables.<RCPurchaseInvoiceItem>concat(_map_2);
      final Function1<RCPurchaseInvoiceItem,Boolean> _function_5 = new Function1<RCPurchaseInvoiceItem,Boolean>() {
          public Boolean apply(final RCPurchaseInvoiceItem it) {
            RCInvoiceType _invoiceType = it.getInvoiceType();
            boolean _equals = Objects.equal(_invoiceType, RCInvoiceType.serviceType);
            return Boolean.valueOf(_equals);
          }
        };
      Iterable<RCPurchaseInvoiceItem> _filter_1 = IterableExtensions.<RCPurchaseInvoiceItem>filter(allInvoiceItems, _function_5);
      final Function1<RCPurchaseInvoiceItem,Double> _function_6 = new Function1<RCPurchaseInvoiceItem,Double>() {
          public Double apply(final RCPurchaseInvoiceItem it) {
            Double _subTotal = it.getSubTotal();
            return _subTotal;
          }
        };
      Iterable<Double> _map_3 = IterableExtensions.<RCPurchaseInvoiceItem, Double>map(_filter_1, _function_6);
      final Function2<Double,Double,Double> _function_7 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce_1 = IterableExtensions.<Double>reduce(_map_3, _function_7);
      final Double serviceInvoceAmount = NumberExtensions.nullsafe(_reduce_1);
      final Function1<RCCustomerContract,Double> _function_8 = new Function1<RCCustomerContract,Double>() {
          public Double apply(final RCCustomerContract it) {
            Double _serviceAmount = it.getServiceAmount();
            return _serviceAmount;
          }
        };
      Iterable<Double> _map_4 = IterableExtensions.<RCCustomerContract, Double>map(this.contracts, _function_8);
      final Function2<Double,Double,Double> _function_9 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce_2 = IterableExtensions.<Double>reduce(_map_4, _function_9);
      final Double serviceContractAmount = NumberExtensions.nullsafe(_reduce_2);
      double _multiply = ((serviceInvoceAmount).doubleValue() * 0.06);
      double _plus = (1 + 0.06);
      final double serviceInvoiceTax = (_multiply / _plus);
      double _multiply_1 = ((serviceContractAmount).doubleValue() * 0.06);
      double _plus_1 = (1 + 0.06);
      final double serviceContractTax = (_multiply_1 / _plus_1);
      final Function1<RCPurchaseInvoiceItem,Boolean> _function_10 = new Function1<RCPurchaseInvoiceItem,Boolean>() {
          public Boolean apply(final RCPurchaseInvoiceItem it) {
            RCInvoiceType _invoiceType = it.getInvoiceType();
            boolean _equals = Objects.equal(_invoiceType, RCInvoiceType.productType);
            return Boolean.valueOf(_equals);
          }
        };
      Iterable<RCPurchaseInvoiceItem> _filter_2 = IterableExtensions.<RCPurchaseInvoiceItem>filter(allInvoiceItems, _function_10);
      final Function1<RCPurchaseInvoiceItem,Double> _function_11 = new Function1<RCPurchaseInvoiceItem,Double>() {
          public Double apply(final RCPurchaseInvoiceItem it) {
            Double _subTotal = it.getSubTotal();
            return _subTotal;
          }
        };
      Iterable<Double> _map_5 = IterableExtensions.<RCPurchaseInvoiceItem, Double>map(_filter_2, _function_11);
      final Function2<Double,Double,Double> _function_12 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce_3 = IterableExtensions.<Double>reduce(_map_5, _function_12);
      final Double productInvoceAmount = NumberExtensions.nullsafe(_reduce_3);
      final Function1<RCCustomerContract,Double> _function_13 = new Function1<RCCustomerContract,Double>() {
          public Double apply(final RCCustomerContract it) {
            Double _productAmount = it.getProductAmount();
            return _productAmount;
          }
        };
      Iterable<Double> _map_6 = IterableExtensions.<RCCustomerContract, Double>map(this.contracts, _function_13);
      final Function2<Double,Double,Double> _function_14 = new Function2<Double,Double,Double>() {
          public Double apply(final Double d1, final Double d2) {
            double _plus = DoubleExtensions.operator_plus(d1, d2);
            return Double.valueOf(_plus);
          }
        };
      Double _reduce_4 = IterableExtensions.<Double>reduce(_map_6, _function_14);
      final Double productContractAmount = NumberExtensions.nullsafe(_reduce_4);
      double _multiply_2 = ((productInvoceAmount).doubleValue() * 0.17);
      double _plus_2 = (1 + 0.17);
      final double productInvoiceTax = (_multiply_2 / _plus_2);
      double _multiply_3 = ((productContractAmount).doubleValue() * 0.17);
      double _plus_3 = (1 + 0.17);
      final double productContractTax = (_multiply_3 / _plus_3);
      final double allInvoiceAmount = DoubleExtensions.operator_plus(serviceInvoceAmount, productInvoceAmount);
      final double allInvoiceTaxAmount = (serviceInvoiceTax + productInvoiceTax);
      final double allContractTaxAmount = (serviceContractTax + productContractTax);
      double _xifexpression = (double) 0;
      RCProjectMoney _totalContractAmount = this.getTotalContractAmount();
      Double _hostAmount = _totalContractAmount.toHostAmount();
      double _divide = (allInvoiceAmount / (_hostAmount).doubleValue());
      double _minus = (_divide - 1);
      double _abs = Math.abs(_minus);
      boolean _lessEqualsThan = (_abs <= 0.001);
      if (_lessEqualsThan) {
        _xifexpression = allInvoiceTaxAmount;
      } else {
        double _max = Math.max(allInvoiceTaxAmount, allContractTaxAmount);
        _xifexpression = _max;
      }
      _xblockexpression = (_xifexpression);
    }
    return Double.valueOf(_xblockexpression);
  }
  
  public RCProjectMoney getTotalRealEfc() {
    RCProjectMoney _xblockexpression = null;
    {
      RCProjectMoney _totalCustomerContractAmount = this.getTotalCustomerContractAmount();
      final Double contractAmount = _totalCustomerContractAmount.toHostAmount();
      final ArrayList<Integer> totalDayList = CollectionLiterals.<Integer>newArrayList();
      Iterable<? extends Serializable> _xifexpression = null;
      boolean _and = false;
      if (!(this.allTaskDelivered).booleanValue()) {
        _and = false;
      } else {
        Double _nullsafe = NumberExtensions.nullsafe(contractAmount);
        boolean _notEquals = ((_nullsafe).doubleValue() != 0);
        _and = ((this.allTaskDelivered).booleanValue() && _notEquals);
      }
      if (_and) {
        final Function1<RCCustomerContract,Collection<RCCustomerContractMoneyAccept>> _function = new Function1<RCCustomerContract,Collection<RCCustomerContractMoneyAccept>>() {
            public Collection<RCCustomerContractMoneyAccept> apply(final RCCustomerContract it) {
              Collection<RCCustomerContractMoneyAccept> _moneyAccepts = it.getMoneyAccepts();
              return _moneyAccepts;
            }
          };
        Iterable<Collection<RCCustomerContractMoneyAccept>> _map = IterableExtensions.<RCCustomerContract, Collection<RCCustomerContractMoneyAccept>>map(this.contracts, _function);
        Iterable<RCCustomerContractMoneyAccept> _flatten = Iterables.<RCCustomerContractMoneyAccept>concat(_map);
        final Function1<RCCustomerContractMoneyAccept,RCPaymentProgressItem> _function_1 = new Function1<RCCustomerContractMoneyAccept,RCPaymentProgressItem>() {
            public RCPaymentProgressItem apply(final RCCustomerContractMoneyAccept moneyAccept) {
              RCPaymentProgressItem _rCPaymentProgressItem = new RCPaymentProgressItem();
              final Procedure1<RCPaymentProgressItem> _function = new Procedure1<RCPaymentProgressItem>() {
                  public void apply(final RCPaymentProgressItem it) {
                    RCRealMoney _acceptMoney = moneyAccept.getAcceptMoney();
                    Double _hostAmount = _acceptMoney.toHostAmount();
                    Double _nullsafe = NumberExtensions.nullsafe(_hostAmount);
                    double _divide = DoubleExtensions.operator_divide(_nullsafe, contractAmount);
                    double _multiply = (_divide * 100);
                    it.setPayPrecent(Double.valueOf(_multiply));
                    Date _acceptDate = moneyAccept.getAcceptDate();
                    Long _between = DateUtil.between(RCProjectImpl.this.deliverDate, _acceptDate);
                    int _intValue = _between.intValue();
                    it.setTotalDays(Integer.valueOf(_intValue));
                    Integer _totalDays = it.getTotalDays();
                    Integer _last = IterableExtensions.<Integer>last(totalDayList);
                    Integer _nullsafe_1 = NumberExtensions.nullsafe(_last);
                    int _minus = ((_totalDays).intValue() - (_nullsafe_1).intValue());
                    it.setGapDays(Integer.valueOf(_minus));
                    Integer _totalDays_1 = it.getTotalDays();
                    totalDayList.add(_totalDays_1);
                  }
                };
              RCPaymentProgressItem _doubleArrow = ObjectExtensions.<RCPaymentProgressItem>operator_doubleArrow(_rCPaymentProgressItem, _function);
              return _doubleArrow;
            }
          };
        Iterable<RCPaymentProgressItem> _map_1 = IterableExtensions.<RCCustomerContractMoneyAccept, RCPaymentProgressItem>map(_flatten, _function_1);
        _xifexpression = _map_1;
      } else {
        ArrayList<RCSaleContractPayCondition> _newArrayList = CollectionLiterals.<RCSaleContractPayCondition>newArrayList();
        _xifexpression = _newArrayList;
      }
      final Iterable<? extends Serializable> paidData = _xifexpression;
      List<? extends Serializable> _list = IterableExtensions.toList(paidData);
      final Collection<RCPaymentProgressItem> result = ((Collection<RCPaymentProgressItem>) _list);
      boolean _and_1 = false;
      if (!(this.allTaskDelivered).booleanValue()) {
        _and_1 = false;
      } else {
        Double _nullsafe_1 = NumberExtensions.nullsafe(contractAmount);
        boolean _notEquals_1 = ((_nullsafe_1).doubleValue() != 0);
        _and_1 = ((this.allTaskDelivered).booleanValue() && _notEquals_1);
      }
      if (_and_1) {
        RCPaymentProgressItem _rCPaymentProgressItem = new RCPaymentProgressItem();
        final Procedure1<RCPaymentProgressItem> _function_2 = new Procedure1<RCPaymentProgressItem>() {
            public void apply(final RCPaymentProgressItem it) {
              RCRealMoney _totalIncomeAmount = RCProjectImpl.this.getTotalIncomeAmount();
              Double _hostAmount = _totalIncomeAmount.toHostAmount();
              Double _nullsafe = NumberExtensions.nullsafe(_hostAmount);
              double _divide = DoubleExtensions.operator_divide(_nullsafe, contractAmount);
              double _multiply = (_divide * 100);
              double _minus = (100 - _multiply);
              it.setPayPrecent(Double.valueOf(_minus));
              Double _payPrecent = it.getPayPrecent();
              boolean _lessThan = ((_payPrecent).doubleValue() < 0);
              if (_lessThan) {
                it.setPayPrecent(Double.valueOf(0d));
              }
              Date _day = DateUtil.today();
              Long _between = DateUtil.between(RCProjectImpl.this.deliverDate, _day);
              int _intValue = _between.intValue();
              it.setTotalDays(Integer.valueOf(_intValue));
              Integer _totalDays = it.getTotalDays();
              Integer _last = IterableExtensions.<Integer>last(totalDayList);
              Integer _nullsafe_1 = NumberExtensions.nullsafe(_last);
              int _minus_1 = ((_totalDays).intValue() - (_nullsafe_1).intValue());
              it.setGapDays(Integer.valueOf(_minus_1));
            }
          };
        final RCPaymentProgressItem remainData = ObjectExtensions.<RCPaymentProgressItem>operator_doubleArrow(_rCPaymentProgressItem, _function_2);
        result.add(remainData);
      }
      final Procedure1<RCPaymentProgressItem> _function_3 = new Procedure1<RCPaymentProgressItem>() {
          public void apply(final RCPaymentProgressItem it) {
            Double _payPrecent = it.getPayPrecent();
            InputOutput.<Double>println(_payPrecent);
            Integer _totalDays = it.getTotalDays();
            InputOutput.<Integer>println(_totalDays);
            Integer _gapDays = it.getGapDays();
            InputOutput.<Integer>println(_gapDays);
            InputOutput.println();
          }
        };
      IterableExtensions.<RCPaymentProgressItem>forEach(result, _function_3);
      RCProjectMoney _totalEfc = this.getTotalEfc(result);
      _xblockexpression = (_totalEfc);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getTotalEfc() {
    RCProjectMoney _xblockexpression = null;
    {
      final ArrayList<RCPaymentProgressItem> currentItems = CollectionLiterals.<RCPaymentProgressItem>newArrayList();
      final Function1<RCSaleContractPayCondition,RCPaymentProgressItem> _function = new Function1<RCSaleContractPayCondition,RCPaymentProgressItem>() {
          public RCPaymentProgressItem apply(final RCSaleContractPayCondition c) {
            RCPaymentProgressItem _rCPaymentProgressItem = new RCPaymentProgressItem();
            final Procedure1<RCPaymentProgressItem> _function = new Procedure1<RCPaymentProgressItem>() {
                public void apply(final RCPaymentProgressItem it) {
                  currentItems.add(it);
                  Double _payPrecent = c.getPayPrecent();
                  it.setPayPrecent(_payPrecent);
                  Integer _deliverDate = c.getDeliverDate();
                  it.setGapDays(_deliverDate);
                  final Function1<RCPaymentProgressItem,Integer> _function = new Function1<RCPaymentProgressItem,Integer>() {
                      public Integer apply(final RCPaymentProgressItem it) {
                        Integer _gapDays = it.getGapDays();
                        return _gapDays;
                      }
                    };
                  List<Integer> _map = ListExtensions.<RCPaymentProgressItem, Integer>map(currentItems, _function);
                  final Function2<Integer,Integer,Integer> _function_1 = new Function2<Integer,Integer,Integer>() {
                      public Integer apply(final Integer i1, final Integer i2) {
                        int _plus = ((i1).intValue() + (i2).intValue());
                        return Integer.valueOf(_plus);
                      }
                    };
                  Integer _reduce = IterableExtensions.<Integer>reduce(_map, _function_1);
                  Integer _nullsafe = NumberExtensions.nullsafe(_reduce);
                  it.setTotalDays(_nullsafe);
                }
              };
            RCPaymentProgressItem _doubleArrow = ObjectExtensions.<RCPaymentProgressItem>operator_doubleArrow(_rCPaymentProgressItem, _function);
            return _doubleArrow;
          }
        };
      final Iterable<RCPaymentProgressItem> mappedItems = IterableExtensions.<RCSaleContractPayCondition, RCPaymentProgressItem>map(this.payConditions, _function);
      List<RCPaymentProgressItem> _list = IterableExtensions.<RCPaymentProgressItem>toList(mappedItems);
      RCProjectMoney _totalEfc = this.getTotalEfc(_list);
      _xblockexpression = (_totalEfc);
    }
    return _xblockexpression;
  }
  
  public Double getContractProductAmount() {
    final Function1<RCCustomerContract,Double> _function = new Function1<RCCustomerContract,Double>() {
        public Double apply(final RCCustomerContract it) {
          RCProjectMoney _totalContractAmount = it.getTotalContractAmount();
          Double _hostAmount = _totalContractAmount.toHostAmount();
          Double _serviceAmount = it.getServiceAmount();
          double _minus = DoubleExtensions.operator_minus(_hostAmount, _serviceAmount);
          return Double.valueOf(_minus);
        }
      };
    Iterable<Double> _map = IterableExtensions.<RCCustomerContract, Double>map(this.contracts, _function);
    final Function2<Double,Double,Double> _function_1 = new Function2<Double,Double,Double>() {
        public Double apply(final Double d1, final Double d2) {
          double _plus = DoubleExtensions.operator_plus(d1, d2);
          return Double.valueOf(_plus);
        }
      };
    Double _reduce = IterableExtensions.<Double>reduce(_map, _function_1);
    Double _nullsafe = NumberExtensions.nullsafe(_reduce);
    return _nullsafe;
  }
  
  public Double getContractServiceAmount() {
    final Function1<RCCustomerContract,Double> _function = new Function1<RCCustomerContract,Double>() {
        public Double apply(final RCCustomerContract it) {
          Double _serviceAmount = it.getServiceAmount();
          return _serviceAmount;
        }
      };
    Iterable<Double> _map = IterableExtensions.<RCCustomerContract, Double>map(this.contracts, _function);
    final Function2<Double,Double,Double> _function_1 = new Function2<Double,Double,Double>() {
        public Double apply(final Double d1, final Double d2) {
          double _plus = DoubleExtensions.operator_plus(d1, d2);
          return Double.valueOf(_plus);
        }
      };
    Double _reduce = IterableExtensions.<Double>reduce(_map, _function_1);
    Double _nullsafe = NumberExtensions.nullsafe(_reduce);
    return _nullsafe;
  }
  
  public RCProjectMoney getEfc(final Double dayAmount, final Double remainPercent, final Integer rawTotalDays) {
    RCProjectMoney _xblockexpression = null;
    {
      int _xifexpression = (int) 0;
      boolean _lessThan = ((rawTotalDays).intValue() < 0);
      if (_lessThan) {
        _xifexpression = 0;
      } else {
        _xifexpression = rawTotalDays;
      }
      final int totalDays = _xifexpression;
      RCProjectMoney _zeroAmount = this.getZeroAmount();
      final Procedure1<RCProjectMoney> _function = new Procedure1<RCProjectMoney>() {
          public void apply(final RCProjectMoney it) {
            double _multiply = ((dayAmount).doubleValue() * totalDays);
            double _multiply_1 = (_multiply * (remainPercent).doubleValue());
            double _divide = (_multiply_1 / 100);
            it.setAmount(Double.valueOf(_divide));
          }
        };
      RCProjectMoney _doubleArrow = ObjectExtensions.<RCProjectMoney>operator_doubleArrow(_zeroAmount, _function);
      _xblockexpression = (_doubleArrow);
    }
    return _xblockexpression;
  }
  
  public RCProjectMoney getTotalEfc(final Collection<RCPaymentProgressItem> payConditions) {
    RCProjectMoney _xblockexpression = null;
    {
      RCProjectMoney _totalContractAmount = this.getTotalContractAmount();
      Double _hostAmount = _totalContractAmount.toHostAmount();
      double _multiply = ((_hostAmount).doubleValue() * 0.12);
      final double dayAmount = (_multiply / 365);
      final Function1<RCPaymentProgressItem,RCProjectMoney> _function = new Function1<RCPaymentProgressItem,RCProjectMoney>() {
          public RCProjectMoney apply(final RCPaymentProgressItem payCondition) {
            RCProjectMoney _xblockexpression = null;
            {
              final Function1<RCPaymentProgressItem,Boolean> _function = new Function1<RCPaymentProgressItem,Boolean>() {
                  public Boolean apply(final RCPaymentProgressItem it) {
                    Integer _totalDays = it.getTotalDays();
                    Integer _totalDays_1 = payCondition.getTotalDays();
                    int _compareTo = _totalDays.compareTo(_totalDays_1);
                    boolean _lessEqualsThan = (_compareTo <= 0);
                    return Boolean.valueOf(_lessEqualsThan);
                  }
                };
              final Iterable<RCPaymentProgressItem> prevAndThisConditions = IterableExtensions.<RCPaymentProgressItem>filter(payConditions, _function);
              final Function1<RCPaymentProgressItem,Boolean> _function_1 = new Function1<RCPaymentProgressItem,Boolean>() {
                  public Boolean apply(final RCPaymentProgressItem it) {
                    Integer _totalDays = it.getTotalDays();
                    Integer _totalDays_1 = payCondition.getTotalDays();
                    int _compareTo = _totalDays.compareTo(_totalDays_1);
                    boolean _lessThan = (_compareTo < 0);
                    return Boolean.valueOf(_lessThan);
                  }
                };
              final Iterable<RCPaymentProgressItem> prevConditions = IterableExtensions.<RCPaymentProgressItem>filter(payConditions, _function_1);
              final Function1<RCPaymentProgressItem,Double> _function_2 = new Function1<RCPaymentProgressItem,Double>() {
                  public Double apply(final RCPaymentProgressItem it) {
                    Double _payPrecent = it.getPayPrecent();
                    return _payPrecent;
                  }
                };
              Iterable<Double> _map = IterableExtensions.<RCPaymentProgressItem, Double>map(prevConditions, _function_2);
              final Function2<Double,Double,Double> _function_3 = new Function2<Double,Double,Double>() {
                  public Double apply(final Double d1, final Double d2) {
                    double _plus = DoubleExtensions.operator_plus(d1, d2);
                    return Double.valueOf(_plus);
                  }
                };
              Double _reduce = IterableExtensions.<Double>reduce(_map, _function_3);
              Double _nullsafe = NumberExtensions.nullsafe(_reduce);
              final double remainPercent = (100 - (_nullsafe).doubleValue());
              final Function1<RCPaymentProgressItem,Integer> _function_4 = new Function1<RCPaymentProgressItem,Integer>() {
                  public Integer apply(final RCPaymentProgressItem it) {
                    Integer _gapDays = it.getGapDays();
                    return _gapDays;
                  }
                };
              Iterable<Integer> _map_1 = IterableExtensions.<RCPaymentProgressItem, Integer>map(prevAndThisConditions, _function_4);
              final Function2<Integer,Integer,Integer> _function_5 = new Function2<Integer,Integer,Integer>() {
                  public Integer apply(final Integer i1, final Integer i2) {
                    int _plus = ((i1).intValue() + (i2).intValue());
                    return Integer.valueOf(_plus);
                  }
                };
              Integer _reduce_1 = IterableExtensions.<Integer>reduce(_map_1, _function_5);
              Integer _nullsafe_1 = NumberExtensions.nullsafe(_reduce_1);
              final int rawTotalDays = ((_nullsafe_1).intValue() - 120);
              ArrayList<Object> _newArrayList = CollectionLiterals.<Object>newArrayList(Double.valueOf(dayAmount), Double.valueOf(remainPercent), Integer.valueOf(rawTotalDays));
              final Function1<Object,String> _function_6 = new Function1<Object,String>() {
                  public String apply(final Object it) {
                    String _string = ((Number)it).toString();
                    return _string;
                  }
                };
              List<String> _map_2 = ListExtensions.<Object, String>map(_newArrayList, _function_6);
              String _join = IterableExtensions.join(_map_2, ",");
              InputOutput.<String>println(_join);
              RCProjectMoney _efc = RCProjectImpl.this.getEfc(Double.valueOf(dayAmount), Double.valueOf(remainPercent), Integer.valueOf(rawTotalDays));
              _xblockexpression = (_efc);
            }
            return _xblockexpression;
          }
        };
      final Iterable<RCProjectMoney> eachEfc = IterableExtensions.<RCPaymentProgressItem, RCProjectMoney>map(payConditions, _function);
      RCExchangeRate _defaultExchangeRate = this.getDefaultExchangeRate();
      RCProjectMoney _sum = Moneys.sum(eachEfc, _defaultExchangeRate);
      _xblockexpression = (_sum);
    }
    return _xblockexpression;
  }
  
  public Collection<RCPurchaseIncomeRequest> getAllPurchaseIncomeRequests(final RCCustomerContract contract) {
    IGenericQuery<RCPurchaseIncomeRequest> query=getObjectFactory().createGenericQuery(RCPurchaseIncomeRequest.class,"select pr from com.shrct.businessprocess.purchase.impl.RCPurchaseIncomeRequestImpl as pr   where (((pr.project) = (:this)) and ((pr.customerContract) = (:contract))) and  pr.active = 1      ").setParameter("this",this).setParameter("contract",contract);
    Collection<RCPurchaseIncomeRequest> _list = query.list();
    return _list;
  }
  
  public RCExchangeRate getDefaultExchangeRate() {
    final Function1<RCExchangeRate,Boolean> _function = new Function1<RCExchangeRate,Boolean>() {
        public Boolean apply(final RCExchangeRate it) {
          CurrencyType _currencyType = it.getCurrencyType();
          boolean _equals = Objects.equal(_currencyType, RCProjectImpl.this.currencyType);
          return Boolean.valueOf(_equals);
        }
      };
    RCExchangeRate _findFirst = IterableExtensions.<RCExchangeRate>findFirst(this.exchangeRates, _function);
    return _findFirst;
  }
  
  public RCCustomerContract createContract(final Procedure1<? super RCCustomerContract> preInit) {
    RCCustomerContract _createAndAddtoContracts = this.createAndAddtoContracts();
    final Procedure1<RCCustomerContract> _function = new Procedure1<RCCustomerContract>() {
        public void apply(final RCCustomerContract customerContract) {
          preInit.apply(customerContract);
          Collection<RCBudget> _budgets = RCProjectImpl.this.cbd.getBudgets();
          final Procedure1<RCBudget> _function = new Procedure1<RCBudget>() {
              public void apply(final RCBudget b) {
                RCBudgetContract _createAndAddtoContracts = b.createAndAddtoContracts();
                final Procedure1<RCBudgetContract> _function = new Procedure1<RCBudgetContract>() {
                    public void apply(final RCBudgetContract it) {
                      RCProjectMoney _rCProjectMoney = new RCProjectMoney();
                      final Procedure1<RCProjectMoney> _function = new Procedure1<RCProjectMoney>() {
                          public void apply(final RCProjectMoney it) {
                            it.setAmount(Double.valueOf(0d));
                            RCExchangeRate _defaultExchangeRate = RCProjectImpl.this.getDefaultExchangeRate();
                            it.setExchange(_defaultExchangeRate);
                          }
                        };
                      RCProjectMoney _doubleArrow = ObjectExtensions.<RCProjectMoney>operator_doubleArrow(_rCProjectMoney, _function);
                      it.setAmount(_doubleArrow);
                      it.setCustomerContract(customerContract);
                    }
                  };
                ObjectExtensions.<RCBudgetContract>operator_doubleArrow(_createAndAddtoContracts, _function);
              }
            };
          IterableExtensions.<RCBudget>forEach(_budgets, _function);
          BeanFactory _beanFactory = RCProjectImpl.this.getBeanFactory();
          RCCustomerContractEventsManager _bean = _beanFactory.<RCCustomerContractEventsManager>getBean(RCCustomerContractEventsManager.class);
          _bean.fireCreated(customerContract);
        }
      };
    RCCustomerContract _doubleArrow = ObjectExtensions.<RCCustomerContract>operator_doubleArrow(_createAndAddtoContracts, _function);
    return _doubleArrow;
  }
  
  public void updateContract(final RCCustomerContract customerContract, final Procedure1<? super RCCustomerContract> updater) {
    updater.apply(customerContract);
    BeanFactory _beanFactory = this.getBeanFactory();
    RCCustomerContractEventsManager _bean = _beanFactory.<RCCustomerContractEventsManager>getBean(RCCustomerContractEventsManager.class);
    _bean.fireUpdateded(customerContract);
  }
  
  public void deleteContract(final RCCustomerContract contract) {
    Collection<RCBudget> _budgets = this.cbd.getBudgets();
    final Procedure1<RCBudget> _function = new Procedure1<RCBudget>() {
        public void apply(final RCBudget b) {
          Collection<RCBudgetContract> _contracts = b.getContracts();
          final Function1<RCBudgetContract,Boolean> _function = new Function1<RCBudgetContract,Boolean>() {
              public Boolean apply(final RCBudgetContract it) {
                RCCustomerContract _customerContract = it.getCustomerContract();
                boolean _equals = Objects.equal(_customerContract, contract);
                return Boolean.valueOf(_equals);
              }
            };
          Iterable<RCBudgetContract> _filter = IterableExtensions.<RCBudgetContract>filter(_contracts, _function);
          List<RCBudgetContract> _list = IterableExtensions.<RCBudgetContract>toList(_filter);
          final Procedure1<RCBudgetContract> _function_1 = new Procedure1<RCBudgetContract>() {
              public void apply(final RCBudgetContract c) {
                b.removeFromContracts(c);
              }
            };
          IterableExtensions.<RCBudgetContract>forEach(_list, _function_1);
        }
      };
    IterableExtensions.<RCBudget>forEach(_budgets, _function);
    this.removeFromContracts(contract);
    BeanFactory _beanFactory = this.getBeanFactory();
    RCCustomerContractEventsManager _bean = _beanFactory.<RCCustomerContractEventsManager>getBean(RCCustomerContractEventsManager.class);
    _bean.fireDeleted(contract);
  }
  
  public RCProjectMoney getZeroAmount() {
    RCProjectMoney _rCProjectMoney = new RCProjectMoney();
    final Procedure1<RCProjectMoney> _function = new Procedure1<RCProjectMoney>() {
        public void apply(final RCProjectMoney it) {
          it.setAmount(Double.valueOf(0d));
          RCExchangeRate _exchangeRate = RCProjectImpl.this.cbd.getExchangeRate();
          it.setExchange(_exchangeRate);
        }
      };
    RCProjectMoney _doubleArrow = ObjectExtensions.<RCProjectMoney>operator_doubleArrow(_rCProjectMoney, _function);
    return _doubleArrow;
  }
  
  public RCProject update(final Function1<? super RCProject,? extends RCProject> preInit) {
    RCProject _apply = preInit.apply(this);
    return _apply;
  }
  
  public Boolean isCurrentUserSaler() {
    boolean _xblockexpression = false;
    {
      BeanFactory _beanFactory = this.getBeanFactory();
      final ISystemUserService systemUserService = _beanFactory.<ISystemUserService>getBean(ISystemUserService.class);
      User _currentUser = systemUserService.getCurrentUser();
      final RCEmployee curUser = ((RCEmployeeUser) _currentUser).getEmployee();
      final Function1<RCProjectSaleAssignment,RCEmployee> _function = new Function1<RCProjectSaleAssignment,RCEmployee>() {
          public RCEmployee apply(final RCProjectSaleAssignment it) {
            RCEmployee _employee = it.getEmployee();
            return _employee;
          }
        };
      Iterable<RCEmployee> _map = IterableExtensions.<RCProjectSaleAssignment, RCEmployee>map(this.salers, _function);
      final List<RCEmployee> s = IterableExtensions.<RCEmployee>toList(_map);
      final Function1<RCEmployee,RCEmployee> _function_1 = new Function1<RCEmployee,RCEmployee>() {
          public RCEmployee apply(final RCEmployee it) {
            RCEmployee _directManager = it.getDirectManager();
            return _directManager;
          }
        };
      List<RCEmployee> _map_1 = ListExtensions.<RCEmployee, RCEmployee>map(s, _function_1);
      final List<RCEmployee> sManagers = IterableExtensions.<RCEmployee>toList(_map_1);
      boolean _or = false;
      boolean _contains = s.contains(curUser);
      if (_contains) {
        _or = true;
      } else {
        boolean _contains_1 = sManagers.contains(curUser);
        _or = (_contains || _contains_1);
      }
      _xblockexpression = (_or);
    }
    return Boolean.valueOf(_xblockexpression);
  }
  
  public Boolean isCurrentUserBusinessMan() {
    boolean _xblockexpression = false;
    {
      BeanFactory _beanFactory = this.getBeanFactory();
      final ISystemUserService systemUserService = _beanFactory.<ISystemUserService>getBean(ISystemUserService.class);
      BeanFactory _beanFactory_1 = this.getBeanFactory();
      RCBusinessProcessorRoleProvider _bean = _beanFactory_1.<RCBusinessProcessorRoleProvider>getBean(RCBusinessProcessorRoleProvider.class);
      final Collection<RCEmployee> bizMans = _bean.getParties();
      User _currentUser = systemUserService.getCurrentUser();
      final RCEmployee curUser = ((RCEmployeeUser) _currentUser).getEmployee();
      boolean _contains = bizMans.contains(curUser);
      _xblockexpression = (_contains);
    }
    return Boolean.valueOf(_xblockexpression);
  }
  
  public void contractSigned(final Date contractDate) {
    this.earlyBuildInfo.setIsEarlyBuild(Boolean.valueOf(false));
    this.earlyBuildInfo.setActuralContractDate(contractDate);
    BeanFactory _beanFactory = this.getBeanFactory();
    RCProjectEventsManager _bean = _beanFactory.<RCProjectEventsManager>getBean(RCProjectEventsManager.class);
    _bean.fireContractSigned(this, contractDate);
  }
  
  public void diagnose(final IDiagnoseAcceptor acceptor) {
    boolean _and = false;
    boolean _notEquals = (!Objects.equal(this.earlyBuildInfo, null));
    if (!_notEquals) {
      _and = false;
    } else {
      Boolean _isEarlyBuild = this.earlyBuildInfo.getIsEarlyBuild();
      _and = (_notEquals && (_isEarlyBuild).booleanValue());
    }
    if (_and) {
      DiagnoseItem _diagnoseItem = new DiagnoseItem();
      final Procedure1<DiagnoseItem> _function = new Procedure1<DiagnoseItem>() {
          public void apply(final DiagnoseItem it) {
            it.setDiagnoseKey("EARLYBUILD");
            Long _id = RCProjectImpl.this.getId();
            it.setEntityId(_id);
            it.setDomainObject(RCProjectImpl.this);
            Class<? extends Object> _class = RCProjectImpl.this.getClass();
            String _name = _class.getName();
            it.setEntityType(_name);
            it.setMessage("\u9879\u76EE\u4E3AEarly Build \u9879\u76EE");
          }
        };
      DiagnoseItem _doubleArrow = ObjectExtensions.<DiagnoseItem>operator_doubleArrow(_diagnoseItem, _function);
      acceptor.accept(_doubleArrow);
      Date _planContractDate = this.earlyBuildInfo.getPlanContractDate();
      long _time = _planContractDate.getTime();
      Date _now = DateUtil.now();
      long _time_1 = _now.getTime();
      boolean _lessThan = (_time < _time_1);
      if (_lessThan) {
        DiagnoseItem _diagnoseItem_1 = new DiagnoseItem();
        final Procedure1<DiagnoseItem> _function_1 = new Procedure1<DiagnoseItem>() {
            public void apply(final DiagnoseItem it) {
              it.setDiagnoseKey("EARLYBUILD-OUTDATE");
              Long _id = RCProjectImpl.this.getId();
              it.setEntityId(_id);
              it.setDomainObject(RCProjectImpl.this);
              Class<? extends Object> _class = RCProjectImpl.this.getClass();
              String _name = _class.getName();
              it.setEntityType(_name);
              it.setMessage("Early Build \u9879\u76EE\u7684\u9884\u5B9A\u7B7E\u7EA6\u65E5\u8FC7\u671F");
            }
          };
        DiagnoseItem _doubleArrow_1 = ObjectExtensions.<DiagnoseItem>operator_doubleArrow(_diagnoseItem_1, _function_1);
        acceptor.accept(_doubleArrow_1);
      }
    }
    this.cbd.diagnose(acceptor);
    final Procedure1<RCCustomerContract> _function_2 = new Procedure1<RCCustomerContract>() {
        public void apply(final RCCustomerContract it) {
          it.diagnose(acceptor);
        }
      };
    IterableExtensions.<RCCustomerContract>forEach(this.contracts, _function_2);
  }
  
  @OneToMany(targetEntity = RCActualCostReportImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }, mappedBy = "project")
  private Collection<RCActualCostReport> reports = new java.util.ArrayList<com.shrct.businessprocess.project.RCActualCostReport>();;
  
  public Collection<RCActualCostReport> getReports() {
    return this.reports;
  }
  
  public RCActualCostReport createAndAddtoReports() {
    getReports().size();
    com.shrct.businessprocess.project.RCActualCostReport rCActualCostReport = new com.shrct.businessprocess.project.impl.RCActualCostReportImpl(this);
    getObjectFactory().create(rCActualCostReport);
    getReports().add(rCActualCostReport);
    return rCActualCostReport;
    
  }
  
  public RCActualCostReport createAndAddtoReports(final Procedure1<RCActualCostReport> updater) {
    getReports().size();
    com.shrct.businessprocess.project.RCActualCostReport rCActualCostReport = new com.shrct.businessprocess.project.impl.RCActualCostReportImpl(this);
    getObjectFactory().create(rCActualCostReport);
    getReports().add(rCActualCostReport);
    return rCActualCostReport;
    
  }
  
  public RCProject removeAllReports() {
    for(RCActualCostReport obj : this.reports){
    	getObjectFactory().delete(obj);
    }
    this.reports.clear();
    return this;	
    
  }
  
  public RCProject removeFromReports(final RCActualCostReport rCActualCostReport) {
    this.reports.remove(rCActualCostReport);
    getObjectFactory().delete(rCActualCostReport);
    return this;
    
  }
  
  public RCActualCostReport getlastFixedActualCostReport() {
    IGenericQuery<RCActualCostReport> query=getObjectFactory().createGenericQuery(RCActualCostReport.class,"select e from com.shrct.businessprocess.project.impl.RCActualCostReportImpl as e   where (((e.isFixed) = (true)) and ((e.project) = (:this))) and  e.active = 1  order by e.toDate DESC    limit 1  ").setParameter("this",this);
    Collection<RCActualCostReport> _list = query.list();
    RCActualCostReport _head = IterableExtensions.<RCActualCostReport>head(_list);
    return _head;
  }
  
  public Collection<RCActualCostReport> getAllFixedActualCostReport() {
    IGenericQuery<RCActualCostReport> query=getObjectFactory().createGenericQuery(RCActualCostReport.class,"select e from com.shrct.businessprocess.project.impl.RCActualCostReportImpl as e   where (((e.isFixed) = (true)) and ((e.project) = (:this))) and  e.active = 1  order by e.toDate DESC    ").setParameter("this",this);
    Collection<RCActualCostReport> _list = query.list();
    return _list;
  }
  
  public void fixActuralCostReport() {
    final RCActualCostReport lastFixedReport = this.getlastFixedActualCostReport();
    RCActualCostReport _createAndAddtoReports = this.createAndAddtoReports();
    final Procedure1<RCActualCostReport> _function = new Procedure1<RCActualCostReport>() {
        public void apply(final RCActualCostReport report) {
          Date _now = DateUtil.now();
          report.setToDate(_now);
          report.setPrevReport(lastFixedReport);
          report.setIsFixed(Boolean.valueOf(true));
          report.performCalculate();
        }
      };
    ObjectExtensions.<RCActualCostReport>operator_doubleArrow(_createAndAddtoReports, _function);
  }
  
  public Collection<RCActualCostReport> getCurrentActuralCostReports() {
    List<RCActualCostReport> _xblockexpression = null;
    {
      final RCActualCostReport lastFixedReport = this.getlastFixedActualCostReport();
      Collection<RCActualCostReport> _allFixedActualCostReport = this.getAllFixedActualCostReport();
      final Procedure1<Collection<RCActualCostReport>> _function = new Procedure1<Collection<RCActualCostReport>>() {
          public void apply(final Collection<RCActualCostReport> it) {
            RCActualCostReport _createAndAddtoReports = RCProjectImpl.this.createAndAddtoReports();
            final Procedure1<RCActualCostReport> _function = new Procedure1<RCActualCostReport>() {
                public void apply(final RCActualCostReport report) {
                  Date _now = DateUtil.now();
                  report.setToDate(_now);
                  report.setPrevReport(lastFixedReport);
                  report.performCalculate();
                }
              };
            RCActualCostReport _doubleArrow = ObjectExtensions.<RCActualCostReport>operator_doubleArrow(_createAndAddtoReports, _function);
            it.add(_doubleArrow);
          }
        };
      final Collection<RCActualCostReport> reports = ObjectExtensions.<Collection<RCActualCostReport>>operator_doubleArrow(_allFixedActualCostReport, _function);
      final Function1<RCActualCostReport,Date> _function_1 = new Function1<RCActualCostReport,Date>() {
          public Date apply(final RCActualCostReport it) {
            Date _toDate = it.getToDate();
            return _toDate;
          }
        };
      List<RCActualCostReport> _sortBy = IterableExtensions.<RCActualCostReport, Date>sortBy(reports, _function_1);
      List<RCActualCostReport> _reverse = ListExtensions.<RCActualCostReport>reverse(_sortBy);
      _xblockexpression = (_reverse);
    }
    return _xblockexpression;
  }
  
  public RCActualCostReport getTempActualCostReport() {
    RCActualCostReport _xblockexpression = null;
    {
      final RCActualCostReport lastFixedReport = this.getlastFixedActualCostReport();
      RCActualCostReport _createAndAddtoReports = this.createAndAddtoReports();
      final Procedure1<RCActualCostReport> _function = new Procedure1<RCActualCostReport>() {
          public void apply(final RCActualCostReport report) {
            Date _now = DateUtil.now();
            report.setToDate(_now);
            report.setPrevReport(lastFixedReport);
            report.performCalculate();
          }
        };
      RCActualCostReport _doubleArrow = ObjectExtensions.<RCActualCostReport>operator_doubleArrow(_createAndAddtoReports, _function);
      _xblockexpression = (_doubleArrow);
    }
    return _xblockexpression;
  }
  
  @JoinColumn(name = "stat_id")
  @OneToOne(targetEntity = RCProjectStatImpl.class, cascade = CascadeType.ALL)
  private RCProjectStat stat;
  
  public RCProjectStat getStat() {
    return this.stat;
  }
  
  public RCProject setStat(final RCProjectStat stat) {
    this.stat = stat;
    return this;			
    
  }
  
  public static RCProject create(final IObjectFactory objectFactory) {
    com.shrct.businessprocess.project.RCProject rCProject = new com.shrct.businessprocess.project.impl.RCProjectImpl(
    );
    objectFactory.create(rCProject);
    return rCProject;			
    
  }
  
  public static RCProject createRCProjectImpl(final IObjectFactory objectFactory, final Procedure1<RCProject> init) {
    com.shrct.businessprocess.project.RCProject rCProject = new com.shrct.businessprocess.project.impl.RCProjectImpl(
    );
    objectFactory.create(rCProject);
    init.apply(rCProject);
    
    return rCProject;			
    
  }
  
  public RCProjectProxy toProxy() {
    com.shrct.businessprocess.project.proxy.RCProjectProxy proxy = new com.shrct.businessprocess.project.proxy.RCProjectProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    proxy.setInternalStatus(this.getInternalStatus().name());
    return proxy;
    
  }
}
